package com.ylyq.ylxx.controller;

import com.ylyq.ylxx.model.ResponseData;
import com.ylyq.ylxx.model.bean.SendQuestion;
import com.ylyq.ylxx.model.request.DeleteAnserRequest;
import com.ylyq.ylxx.model.request.SendQuestionRequest;
import com.ylyq.ylxx.service.IChatService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaweichao
 * @since 2020-10-19
 */
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Autowired
    private IChatService iChatService;

    @PostMapping("/sendQuestion")
    @ApiOperation(value = "发送问题", response = SendQuestion.class)
//    public ResponseData sendQuestion(@RequestParam("question") @ApiParam(value = "question", required = true) String question) {
    public ResponseData sendQuestion(@RequestBody SendQuestionRequest sendQuestionRequest) {
        return new ResponseData(ResponseData.Result.SUCCESS,iChatService.sendQuestion(sendQuestionRequest.getQuestion()));
    }

    @PostMapping("/submitAnser")
    @ApiOperation(value = "提交答案")
    public ResponseData submitAnser(@RequestBody SendQuestionRequest sendQuestionRequest) {
        iChatService.submitAnser(sendQuestionRequest.getQuestion(),sendQuestionRequest.getAnser());
        return new ResponseData(ResponseData.Result.SUCCESS);
    }

    @PostMapping("/importChat")
    @ApiOperation(value = "录入聊天记录")
    public ResponseData importChat(@RequestParam("file") MultipartFile file) {
        iChatService.importChat(file);
        return new ResponseData(ResponseData.Result.SUCCESS);
    }

    @PostMapping("/deleteAnser")
    @ApiOperation(value = "删除聊天记录")
    public ResponseData deleteAnser(@RequestBody DeleteAnserRequest deleteAnserRequest) {
        iChatService.deleteAnser(deleteAnserRequest);
        return new ResponseData(ResponseData.Result.SUCCESS);
    }

}
